﻿using AutoMapper;
using MediatR;
using Traceability.App.Applications.Command.Enterprise;
using Traceability.Domain.Entity;
using Traceability.Domain.Repository;
using Traceability.Enum;

namespace Traceability.App.Applications.CommandHand.Enterprise
{
    public class AddEnterpriseCommandHand : IRequestHandler<AddEnterpriseCommand, ApiResult<int>>
    {
        private readonly IBaseRepository<EnterpriseModel> _enterprise;
        private readonly IMapper mapper;

        public AddEnterpriseCommandHand(IBaseRepository<EnterpriseModel> enterprise, IMapper mapper)
        {
            _enterprise = enterprise;
            this.mapper = mapper;
        }



        public Task<ApiResult<int>> Handle(AddEnterpriseCommand request, CancellationToken cancellationToken)
        {
            var result=new ApiResult<int>();
            var enter=mapper.Map<EnterpriseModel>(request);
            _enterprise.Add(enter);
            result.Message = "添加成功";
                

            return  Task.FromResult(result);
        }
    }
}
